package com.yanqu.road.server.cmd.cricket;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cricket.CricketProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.cricket.CricketModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：xx
 */
@Cmd(code = GameProtocol.S_CRICKET_EQUIP_CRICKET, desc = "装备")
public class EquipCricketCmd extends AbstractCommand {
    private int cricketId;
    private int patronsId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CricketProto.EquipCricketReqMsg msg = CricketProto.EquipCricketReqMsg.parseFrom(packet.getBytes());
        cricketId = msg.getCricketId();
        patronsId = msg.getPatronsId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(CricketModule.class).equipCricket(cricketId, patronsId);
    }

    @Override
    public void sendData(GamePlayer player) {
        CricketProto.EquipCricketRespMsg.Builder respMsg = CricketProto.EquipCricketRespMsg.newBuilder();
        respMsg.setRet(ret);
        player.sendPacket(ClientProtocol.U_CRICKET_EQUIP_CRICKET, respMsg);
    }
}
